import os

def pair(args):
	for i in range(len(args)):
		for b in args[i+1:]:
			yield (args[i],b)

def pair2(arg, args):
	for a in args:
		yield (arg, a)

#agents
players = ['greedyscore', 'greedysmartscore', 'greedymob', 'greedystab', 'naive', 'scoremax', 'smartscoremax', 'mobimax', 'mobiplus', 'stabmax', 'mobstab', 'most', 'scoreab', 'smartscoreab', 'mobab', 'mobplusab', 'stabab', 'mobstabab', 'mostab']
heuristics = {'score' : ['greedyscore', 'scoremax', 'scoreab'],
	      'smartscore' : ['greedysmartscore', 'smartscoremax', 'smartscoreab'],
	      'mobility' : ['greedymob', 'mobimax', 'mobab'],
	      'stability' : ['greedystab', 'stabmax', 'stabab']}

#indexing of games
header = """GAME: %(p1)s versus %(p2)s
Time: %(t)d
%(p1)s Black, %(p2)s White - %(o1)s
%(p2)s Black, %(p1)s White - %(o2)s
"""

#othello commands
cmd=["othellosim -b %(p1)s -w %(p2)s -g 3 -t %(t)d -o %(o1)s",
     "othellosim -b %(p2)s -w %(p1)s -g 3 -t %(t)d -o %(o2)s"]

d = {'p1':'',
     'p2':'',
     't':0,
     'o1':"%(p1)s-Vs-%(p2)s-%(t)d.txt",
     'o2':"%(p2)s-Vs-%(p1)s-%(t)d.txt"}



index = open('index.txt', 'w')

index.write("BASE PLAYER RANKINGS\n")
#base rankings: vs random
d['t']=100
for d['p1'], d['p2'] in pair2('random',players): 
	map(lambda l : os.system(l %d %d), cmd)
	index.write(header %d %d)


index.write("SEARCH COMPARISONS ACROSS HEURISTICS\n")
#search strategy rankings across constant heuristic
d['t']=500
for h, a in heuristics.iteritems():
	index.write(h + '\n')
	for d['p1'], d['p2'] in pair(a):
		map(lambda l : os.system(l %d %d), cmd)
		index.write(header %d %d)

#index.write("DIRECT PLAYER COMPETITION\n")
#head-to-head player competion in three tiers, 100ms, 1s, 10s
#for d['p1'], d['p2'] in pair(players):
#	for d['t'] in [100, 1000, 10000]:
#		map(lambda l : os.system(l %d %d), cmd)
#		index.write(header %d %d)
	
index.close()